<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8"/>
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="no" name="apple-touch-fullscreen">
    <meta content="telephone=no,address=no" name="format-detection">
    <title>$!config.title</title>
    <link href="$!webPath/resources/style/system/front/wap/css/style.css" rel="stylesheet" type="text/css">
    <script src="$!webPath/resources/style/system/front/wap/js/jquery-1.10.2.min.js"></script>
    <script>

        function goods_count_adjust(gc_id, store_id, count, gift_id) {
            jQuery.post("$!webPath/goods_count_adjust1.htm", {
                "cart_id": gc_id,
                "store_id": store_id,
                "count": count
            }, function (data) {
                if (data.error == "100") {
                    if (store_id) {
                        jQuery("#total_price_" + store_id).html(data.sc_total_price); //设置店铺的总价
                    }
                }
                if (data.error == "200") {
                    alert("库存不足，请重新选择数量！");
                    jQuery("#goods_count_" + gc_id).val(jQuery("#goods_count_" + gc_id).attr("goods_count"));
                }
                if (data.error == "300") {
                    alert("团购库存不足，请重新选择数量！");
                }
            }, "json");
        }

        //发送状态
        function goods_count_status(gc_id, store_id, status) {
            jQuery.getJSON("$!webPath/send_status.htm", {
                "cart_id": gc_id,
                "store_id": store_id,
                "status": status
            }, function (data) {
                jQuery("#total_price_" + store_id).html(data.sc_total_price); //设置店铺的总价
            });
        }


        //获取总价
        function goods_count_total_price(store_id,status) {
            jQuery.getJSON("$!webPath/totalPrice.htm", {
                "store_id": store_id,
                "status": status
            }, function (data) {
                if (store_id) {
                    jQuery("#total_price_" + store_id).html(data.goods_total_price); //设置店铺的总价
                }
            });
        }





        //购物车提交
        function confirm_cart(sc_id) {

            jQuery("#cart_" + sc_id).hide();
            jQuery("#cart_" + sc_id).attr("status", "submit");
            if (jQuery("form[id^=cart_][status=no_submit]").length == 0) {
                jQuery("#cart_" + sc_id).attr("target", "_self");
            }
            jQuery("#cart_" + sc_id).submit();
        }

        jQuery(document).ready(function () {

            //减少数量
            jQuery("a[id^=count_down]").click(
                    function () {
                        var gc_id = jQuery(this).attr("gc_id");
                        var store_id = jQuery(this).attr("store_id");
                        var count = jQuery("#goods_count_" + gc_id).val();

                        var f_sale_type = parseInt(jQuery(this).attr("f_sale_type"));
                        var gift_id = jQuery(this).attr("check_gift_id");
                        if (f_sale_type == 0) {
                            if (count > 1) {
                                count--;
                                jQuery("#goods_count_" + gc_id).val(count);
                                goods_count_adjust(gc_id, store_id, count, gift_id);
                            }
                        } else {
                            alert("F码商品一次只能购买一件!");
                        }

                    });

            //添加数量
            jQuery("a[id^=count_up]").click(
                    function () {
                        var gc_id = jQuery(this).attr("gc_id");
                        var store_id = jQuery(this).attr("store_id");
                        var count = jQuery("#goods_count_" + gc_id).val();

                        var f_sale_type = parseInt(jQuery(this).attr("f_sale_type"));
                        var gift_id = jQuery(this).attr("check_gift_id");
                        if (f_sale_type == 0) {
                            if (count > 0) {
                                count++;
                                jQuery("#goods_count_" + gc_id).val(count);
                                goods_count_adjust(gc_id, store_id, count, gift_id);
                            }
                        } else {
                            alert("F码商品一次只能购买一件!");
                        }
                    });

            //编辑数量
            jQuery("input[id^=goods_count_]").keyup(
                    function () {
                        var gc_id = jQuery(this).attr("gc_id");
                        var count = jQuery("#goods_count_" + gc_id).val().replace(/\D/g, '');
                        var store_id = jQuery(this).attr('store_id');

                        var f_sale_type = parseInt(jQuery(this).attr("f_sale_type"));
                        var gift_id = jQuery(this).attr("check_gift_id");
                        if (count == "") {
                            count = 1;
                        }
                        if (f_sale_type == 0) {
                            if (count > 0) {
                                goods_count_adjust(gc_id, store_id, count, gift_id);
                            }
                            if (count == 0) {
                                jQuery("#goods_count_" + gc_id).val("1");
                                goods_count_adjust(gc_id, store_id, 1, gift_id);
                            }
                        } else {
                            alert("F码商品一次只能购买一件!");
                            jQuery("#goods_count_" + gc_id).val("1");
                        }
                    });

            //选择商品
            jQuery("input[id^=select_goods_]").click(function () {
                var gc_id = jQuery(this).attr('gc_id');
                var store_id = jQuery(this).attr('store_id');
                var  status =  0;
                if (jQuery(this).attr("checked")){
                    $(this).removeAttr("checked");
                    status =  0;
                }else{
                    $(this).attr("checked",'true');
                    status =  1;
                }

                //判断是否为全选
                var car_page_li = jQuery('#store_'+store_id).find('li');
                if (car_page_li.find('input[type=checkbox]:checked').length == car_page_li.find('input[type=checkbox]').length){
                    jQuery("#ids_"+store_id).prop('checked',true);
                }else{
                    jQuery("#ids_"+store_id).prop('checked',false);
                }

                goods_count_status(gc_id, store_id, status);

            })


            //店里商品实现全选
            jQuery("input[id^=ids_]").click(function () {

                var car_page = $(this).parents('.car_page');
                var store_id = jQuery(this).attr('store_id');
                var status =  0;

                if (jQuery(this).prop("checked")){
                    car_page.find('li').find('input[type=checkbox]').prop('checked',true);
                    status =  1;
                }else{
                    car_page.find('li').find('input[type=checkbox]').prop("checked", false);
                    status =  0;
                }

                goods_count_total_price(store_id,status);


            })


            //打开页面清除所有商品选择
            //jQuery("span.go_count a").css("background", "#999");

            /* jQuery("div[id^=gift_inner_]").find("input").each(function() {
             jQuery(this).click(function() {
             var test = jQuery(this).attr("checked");
             if (this.checked) {
             jQuery(this).parent().parent().parent().siblings().removeClass("this").find("input").prop("checked", false);
             jQuery(this).parent().parent().parent().addClass("this");
             }
             });
             }); */
        });

        //删除商品
        function cart_remove(objid, del_store_id) {

            //var type = arguments[1];
            var type = "1";
            var method = function () {
                    jQuery.post("$!webPath/remove_goods_cart.htm",
                        {
                            "id": objid,
                            "store_id": del_store_id
                        },
                        function (data) {

                            if (type == "one_combin") {
                                window.location.href = "$!webPath/goods_cart0.htm";
                            } else {
                                window.location.reload();

                            }
                        }, "json");

            };

            if (type == "one_combin") {
                if (confirm("删除后其他套装商品将不享受优惠！")) {
                    method();
                }

            }
            if (type == "all_combin") {
                if (confirm("确定删除整个组合套装吗！")) {
                    method();
                }
            }
            if (type == "1" || type == undefined) {
                if (confirm("确定删除已选中的商品！")) {
                    method();
                }
            }

        }

    </script>

    <style>
        label {
            display: inline-block;
            cursor: pointer;
            position: relative;
            padding-left: 25px;
            margin-right: 15px;
            font-size: 13px;
            background-color: #F94D4D;
            margin-top: 20px;
        }

        .wrapper {
            width: 500px;
            margin: 50px auto;
        }

        input[type=radio], input[type=checkbox] {
            display: none;
        }

        label:before {
            content: "";
            display: inline-block;
            width: 20px;
            height: 20px;
            margin-right: 10px;
            position: absolute;
            left: 0;
            bottom: 0;
            background-color: #D8D8D8;
        }

        .radio label:before {
            border-radius: 8px;
        }

        .checkbox label {
            margin-bottom: 10px;
        }

        .checkbox label:before {
            border-radius: 3px;
        }

        input[type=checkbox]:checked + label:before {
            content: "\2713";
            font-size: 15px;
            color: #f3f3f3;
            text-align: center;
            line-height: 18px;
            background-color: #F94D4D;
        }
    </style>
</head>

<body>
<div class="phone_hd">
    <a class="back" href="javascript:history.go(-1);">
        <img src="$!webPath/resources/style/system/front/wap/images/back.png" width="25" height="25">
    </a>
    购物车
    <a class="edit" href="$!webPath/wap/index.htm">
        <img src="$!webPath/resources/style/system/front/wap/images/home.png" width="25" height="25">
    </a>
</div>

#if($!cart.size()>0)
#foreach($sc in $cart)
<div class="car_store" id="store_$!{sc.store.id}">
    <form status="no_submit" method="post" name="cart_$!{sc.store.id}" id="cart_$!{sc.store.id}"
          action="$!webPath/goods_cart2.htm">
        <input type="hidden" name="giftids" id="giftids" value="">
        <!--购物车-->
        <div class="car_page">
            <dl class="shopvdl_wrap clearfix">
                <dt>
                        <span>
                        #if($!store.store_logo)
                            <a href="$!webPath/store_$!{sc.store.id}.htm?parameter=recommend"><img src="$!webPath/$!{sc.store.store_logo.path}/$!{sc.store.store_logo.name}" width="30" height="30"></a>
                            #else
                            <a href="$!webPath/store_$!{sc.store.id}.htm?parameter=recommend"><img src="$!webPath/$!config.storeImage.path/$!config.storeImage.name" width="30" height="30"></a>
                            #end
                        </span>
                </dt>
                <dd>
                        <span>
                        	<a href="$!webPath/store_$!{sc.store.id}.htm?parameter=recommend">$sc.store.store_name</a>
                        </span>
                </dd>
            </dl>
            <ul>
                <!--普通商品-->
                #foreach($obj in $sc.gcs)
                #if($!obj.goods.goods_main_photo)
                #set($img="$!imageWebServer/$!{obj.goods.goods_main_photo.path}/$!{obj.goods.goods_main_photo.name}_small.$!{obj.goods.goods_main_photo.ext}")
                #else
                #set($img="$!imageWebServer/resources/style/common/images/good.jpg")
                #end
                <li>
                    <div class="li_box">
                        #if($!obj.status==1)
                        <div class="select"><input type="checkbox" id="select_goods_$!{obj.id}" gc_id="$!{obj.id}" store_id="$!{sc.store.id}" f_sale_type="0" checked="checked"></div>
                        #else
                        <div class="select"><input type="checkbox" id="select_goods_$!{obj.id}" gc_id="$!{obj.id}" store_id="$!{sc.store.id}" f_sale_type="0"></div>
                        #end
                        <div class="img">
                            <a href="$!webPath/goods_$!{obj.goods.id}.htm"><img src="$!img" width="60" height="60"></a>
                        </div>
                        <div class="infro">
							<span class="name">
								<a href="$!webPath/goods_$!{obj.goods.id}.htm">$!CommUtil.substring("$!obj.goods.goods_name",30)</a>
							</span>
							<span class="num">
								<a class="minus" href="javascript:void(0);" id="count_down_$!obj.id" gc_id="$!obj.id"
                                   f_sale_type="0" store_id="$!{sc.store.id}">－</a>
								<input name="goods_count_$!obj.id" type="text" id="goods_count_$!obj.id" f_sale_type="0"
                                       value="$!obj.count" gc_id="$!obj.id" goods_count="$!obj.count"
                                       store_id="$!{sc.store.id}">
								<a class="plus" href="javascript:void(0);" id="count_up_$!obj.id" gc_id="$!obj.id"
                                   f_sale_type="0" store_id="$!{sc.store.id}">+</a>
							</span>
                        </div>
                        <div class="fr">
                            <span class="price" id="gc_price$!obj.id">单价:¥$!obj.price</span>
                            <input type="hidden" id="gc_h_price_$!obj.id" value="$!obj.price">
							<span class="del">
								<a href="javascript:void(0);" onclick="cart_remove('$!obj.id','$!sc.store.id');">
									<img src="$!webPath/resources/style/system/front/wap/images/del.png" width="25"
                                         height="25">
								</a>
							</span>
                        </div>
                    </div>
                </li>
                #end
            </ul>

            <div class="car_pay">
                <div class="check">
                    <div class="checkbox">
                        <input type="checkbox" id="ids_$!{sc.store.id}" store_id="$!{sc.store.id}"/>
                        <label style="margin-top: 20px;" for="ids_$!{sc.store.id}"></label>
                    </div>
                </div>
                <div class="total">
                    <p class="price total_pri" id="go_total_price_$!{sc.store.id}">商品总价(不含运费)：<b>¥<span
                            id="total_price_$!{sc.store.id}">$!{sc.total_price}</span></b></p>
				<span id="enough_reduce_money" style="display: none">
					<p id="before_price">商品总额:¥0.00元</p>
					<p id="reduce_price">满就减金额:¥0.00元</p></span>
                </div>
                <a class="paymen_btn" href="javascript:void(0);" onclick="confirm_cart('$!sc.store.id');">结算</a>
            </div>

            <input name="store_id" type="hidden" id="store_id" value="$!{sc.store.id}"/>
        </div>

    </form>
</div>
#end
#else
<div class="car_none"><span><img src="$!webPath/resources/style/system/front/wap/images/car_none.jpg"></span> <b>购物车是空的，去看看商品吧</b>
</div>
<div class="car_none_btn">
    <input type="button" onclick="javascript:window.location.href='$!webPath/wap/index.htm'" value="去购物">
</div>
#end


</body>
</html>